<%@ page language="java" contentType="text/html; charset=UTF-8" 	pageEncoding="UTF-8"%>
<%
  String xm = this.getServletContext().getInitParameter("path");
	String path1 = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+"/"+xm;
%>  
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>添加合同消息</title>
<link href="<%=path1 %>/css/css.css" rel="stylesheet" type="text/css" />

<script src="<%=path1%>/qt/yjs/jquery.min.js"></script>

<!-- 最新的 Bootstrap 核心 JavaScript 文件 -->
<script src="<%=path1%>/qt/yjs/bootstrap.min.js"></script>
 

<link rel="stylesheet" type="text/css" href="<%=path1%>/qt/css/normalize.css" />
		<link rel="stylesheet" type="text/css" href="<%=path1%>/qt/fonts/font-awesome-4.2.0/css/font-awesome.min.css" />
		<link rel="stylesheet" type="text/css" href="<%=path1%>/qt/css/demo.css" />
		<link rel="stylesheet" type="text/css" href="<%=path1%>/qt/css/component.css" />
<link href="../css/css.css" rel="stylesheet" type="text/css" />
<link type="text/css" rel="stylesheet" href="<%=path1%>/scripts/pagekage/utils/widget/jqGrid/redmond/jquery-ui-1.8.2.custom.css"/>
<link type="text/css" rel="stylesheet" href="<%=path1%>/scripts/pagekage/utils/widget/jqGrid/ui.jqgrid.css"/>  


<script type="text/javascript" src="<%=path1%>/scripts/pagekage/utils/widget/jqGrid/jquery.jqGrid.src.js"></script>
<script type="text/javascript" src="<%=path1%>/scripts/pagekage/utils/widget/jqGrid/i18n/grid.locale-cn.js"></script>
<script type="text/javascript" src="<%=path1%>/scripts/pagekage/utils/widget/jqGrid/jquery.jqGrid.min.js"></script>  
<link rel="stylesheet" href="<%=path1%>/qt/ycss/bootstrap.min.css">

<!-- 可选的Bootstrap主题文件（一般不用引入） -->
<link rel="stylesheet" href="<%=path1%>/qt/ycss/bootstrap-theme.min.css">
<style type="text/css">
	body{margin:0;padding:0;font:14px Verdana, Arial, sans-serif;line-height:200%;}
	#content{padding-left:50px;padding-right:50px;}
	#content h2{font-size:18px;color:#1E9300;padding-top:8px;margin-bottom:8px;}
	#content h3{margin-top:8px;margin-bottom:8px;FONT:bold 14px 宋体,tahoma,arial,sans-serif;COLOR:#0033CC;}
	#content div{margin-top:10px;margin-bottom:10px;border:#666 solid 1px;padding:10px;}
	#content span{color:#f00;font-weight:bold;}
	ul, ol{color:#000000;}
	</style>
<!--[if IE 6]>
<script type="text/javascript" src="js/ie6png.js" ></script>
<script type="text/javascript">
DD_belatedPNG.fix('div,ul,li,a,p,img,body,dl,dt,dd');</script>
<![endif]-->
<script type="text/javascript" src="js/lhgcore.js"></script>
<script type="text/javascript" src="js/lhgcalendar.js"></script>
<script type="text/javascript">
function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}
</script>
<script type="text/javascript">

$(document).ready(function(){
	var SeachSql;
	var id;
    var str=window.location.href; //得到listclient的地址
    //alert("str"+str);
    var es=/id=/; 
    es.exec(str); //得到地址后面变量名称
    //alert("es--"+es.exec(str));
    var right=RegExp.rightContext;//得到地址后面变量名称的值
    //alert("right-"+right);

    id=right;//将结果赋值给id
     return select(id);  
});

function select(order_id){
	 $("#order_id").val(order_id);
	$.ajax({
    	url:"./Order/selectOrderAndRoomBySql.do",
        datatype:'json', 
        data:{'SearchSql':"and order_id= '"+order_id+"'"}, // 发送数据   
        error:function(data){  
            alert("出错了,没有这个客户！！");  
       },  
       success:function(data){
    	 console.log("data:"+data);
    	// $("#project_name").val(data.rows[0].project_name);
    	 $("#project_name").val(data.rows[0].project_name);
    	 $("#build_name").val(data.rows[0].build_name);
    	 $("#unit_code").val(data.rows[0].unit_code);
      	 $("#room_code").val(data.rows[0].room_code);
      	 $("#unit_price").val(data.rows[0].unit_price);
      	 $("#total").val(data.rows[0].total);
      	 $("#pay_area").val(data.rows[0].pay_area);
      	 $("#customer_name").val(data.rows[0].customer_name);
      	 $("#customer_name").attr("cid",data.rows[0].customer_id);
      	 $("#deposit").val(data.rows[0].deposit);
      	 $("#pay_type_id").val(data.rows[0].pay_type_name);
      	 $("#order_type").val(data.rows[0].order_type);
      	 $("#build_name").val(data.rows[0].build_name); //楼栋
      	$("#first_party").val(data.rows[0].customer_name);
       }
        });
}
</script>

<script type="text/javascript">
//添加
    function ajaxPost(){
   
        $.ajax({ 	
        data:{customer_name:$("#customer_name").val(),
        	tel:$("#tel").val(),
        	sex:$("input[name='sex']:checked").val(),
        	customer_type:$("input[name='customer_type']:checked").val(),
        	describel:$("#describel").val(),
        	maritalStatus:$("#maritalStatus").val(),
        	address:$("#address").val(),
        	id_number:$("#id_number").val(),
        	
        	profession:$("#profession").val(),
        	income_level:$("#income_level").val(),
        	
        },
        type:"Post",  
        dataType: 'json',  
        url:"./Customer/addCustomer.do", 
        error:function(data){ 
        	alert(data);
             alert("出错了！！");  
        },  
        success:function(data){
        	
        	alert(data);
        	alert('客户信息添加成功！');
        	window.location.href = 'listCustomer.jsp'; 
         }  
         });  
     } 
    // 重置
    function ajaxReset(){
    	$("#customerName").val("");
    	$("#tel").val("");
    	$("input:radio[name='sex']").eq(0).attr("checked",true);
    	$("input:radio[name='customerType']").eq(0).attr("checked",true);
    	$("#paperstType").val("");
		$("#paperstNo").val("");
		$("#eduStatus").val("");
		$("#profession").val("");
		$("#income").val("");
		$("#maritalStatus").val("");
		$("#address").val("");
    }
    
    function selectbuile(){
    	var buildValue = $("#build_name").val();
    	var searchSqlbuider ='';
    	var selectsUnitCode =null;
    	if(!(buildValue==null || buildValue =="")){
    		searchSqlbuider = "and build_id='"+buildValue+"'GROUP by unit_code";
    	}
    	$("#unit_code").empty();
    	  selectsUnitCode = document.getElementById("unit_code");
    	   $.post("./Order/unit/SelectBySql.do",
    	    		  {"seacherSql":searchSqlbuider},
    	    		  function (data) {
    	    			  var text = "请选择单元";
    	    			  var opCustomerName=document.createElement("option");      
    	    	         opCustomerName.setAttribute("value",'');   
    	    			  if(data.rows.length==0){
    	    				text = "没有相应的数据";
    	    			  }
    	    			  opCustomerName.appendChild(document.createTextNode(text)); 
    	    			  selectsUnitCode.appendChild(opCustomerName);
    	    			  for(var a =0; a<data.rows.length;a++){
    	      				var opCustomerName=document.createElement("option");      
    	  		         	opCustomerName.setAttribute("value",data.rows[a].unit_id);        
    	  		         	opCustomerName.appendChild(document.createTextNode(data.rows[a].unit_code)); 
    	  		         	selectsUnitCode.appendChild(opCustomerName);   
    	    			  }
    	    		  });
    	
    }

	function selectunit() {
		//选择房间
		var unitValue = $("#unit_code").val();
		console.log("单元编号" + unitValue);
		var SearchSqlbuider = '';
		var selectsUnitCode = null;
		if (!(unitValue == null || unitValue == "")) {
			SearchSqlbuider = "and unit_id='" + unitValue + "'";
		}
		$("#room_code").empty();
		selectsUnitCode = document.getElementById("room_code");
		$.post("./Order/room/selectBySql.do",
			{"seacherSql" : SearchSqlbuider},
			function(data) {
			var text = "请选择房间";
			var opCustomerName = document.createElement("option");
			opCustomerName.setAttribute("value", '');
			if (data.rows.length == 0) {
				text = "没有相应的数据";
			}
			opCustomerName.appendChild(document.createTextNode(text));
			selectsUnitCode.appendChild(opCustomerName);
			for (var a = 0; a < data.rows.length; a++) {
				var opCustomerName = document.createElement("option");
				opCustomerName.setAttribute("value", data.rows[a].room_id);
				opCustomerName.appendChild(document
						.createTextNode(data.rows[a].room_code));
				selectsUnitCode.appendChild(opCustomerName);
			}
		});
	}
	function selectRoom(){
		//选择房间
		var unitValue = $("#room_code").val();
		console.log("房间编号" + unitValue);
		var SearchSqlbuider = '';
		var selectsUnitCode = null;
		if (!(unitValue == null || unitValue == "")) {
			SearchSqlbuider = "and room_id='" + unitValue + "'";
		}
		$.post("./Order/room/selectBySql.do",
			{"seacherSql" : SearchSqlbuider},
			function(data) {
				
			$("#unit_price").val(data.rows[0].inner_price);
			$("#pay_area").val(data.rows[0].build_up_area);
			$("#total").val((data.rows[0].inner_price)*(data.rows[0].build_up_area));
			});
	}
</script>
<script type="text/javascript">
   function checkcustomerName(){
	  var customerName= $("#customerName").val();
	  if(customerName==""){
		 alert("客户名称不能为空！"); 
		 $("#customerName").focus();
		 return false;
	  }
	  return true;
   }
   function checktel(){
	   var tel=$("#tel").val();
		  if(tel==""){
			 alert("联系电话不能为空！"); 
			 $("#tel").focus();
			 return false;
		  }
		  return true;
   }
   function tel(){
	   var tel=$("#tel").val();
	   var phone=/^1\d{10}$/;
	   var mobile=/^0\d{2,3}-?\d{7,8}$/;
	   if (phone.test(tel) || mobile.test(tel)) { 
		      //alert("号码正确~"); 
		 }else{ 
		      alert("号码有误~"); 
		      $("#tel").focus();
		 };
   }
   function paperstNo(){
	   var no=$("#paperstNo").val();
	   var paperstNo=/^\d{17}([0-9]|X)$/;
	   if (paperstNo.test(no)) { 
		      //alert("身份证号码正确~"); 
		 }else{ 
		      alert("身份证号码有误~"); 
		      $("#paperstNo").focus();
		 };
   }
	function sendMassage() {
		var customer_name =  $("#customer_name").attr("cid");
		     $.ajax({ 	
		    	 data: {
		    	     	"contract_id":customer_name
		    	     	},  
		         dataType: 'json',  
		         url:"../qt/contract/sendMassage.do", 
		         error:function(data){  
		                 alert("系统繁忙");
		         },  
		         success:function(data){
		           $('#myModal').modal('show');
		           var checstr = "已经发送验证信息到您预留手机号\""+data.rows[0]+"\"，请完成验证！谢谢 。";
		           $('#checkmassageid').html(checstr);
		           }  
		   });  
	}
	   function ajaxUpdate123(){
		   var role_id = $('#list4').jqGrid('getGridParam', 'selrow');
			var contract_id= $("#list4").getCell(role_id,"contract_id"); 
	     $.ajax({ 	
	     data: {
	    	 contract_id:contract_id,
	     	cheknum:$("#input-1").val()
	     	},  
	     	type:"Post",  
	     	 async:false, 
	     dataType: 'json',  
	     url:"../qt/contract/checkMassage.do", 
	     error:function(data){  
	    	alert("系统繁忙，请稍后再试！")
	     },  
	     success:function(data){
	    	 if(orderSubmit()){
	    		 //alert(1111)
	    		// window.location.href = "../qt/listContract.jsp";
	    	 }
	         }
	      });  
	    
	  } 
   function orderSubmit(){
	   var bool = false;
	   order_id = $("#order_id").val();
	   first_party = $("#first_party").val();
	   second_party = $("#second_party").val();
	   sign_time = $("#btn").val();
	   contract_content = $("#contract_content").val();
	   contract_total = $("#contract_total").val();
	   room_area = $("#pay_area").val();
	   room_code =  $("#room_code").val();
	 $.ajax({
		 url:"./contract/addContract.do",
		 async:false, 
		 data:{
	       "order_id":order_id,
	       "first_party":first_party,
	       "second_party":second_party,
	       "sign_time":sign_time,
	       "contract_content":contract_content,
	       "contract_total":contract_total,
	       "room_area":room_area,
	       "room_code":room_code
  		  },
  		 success:function(data){
  			  $('#myModal').modal('hide');
	    	  bool =true;
	    	 window.location.href = "listContract.jsp?id=1";
  		 }
	 });  
			 
	    return bool;
   }
  
   </script>
</head>
<body>
	<input type="hidden" id="order_id" />
	<div class="yboxwidth boxcenter">
		<div class="ybox09">
			<table width="100%" border="0" cellspacing="0" cellpadding="0">
				<tr>
					<td style="padding-left: 20px"><table border="0"
							cellspacing="0" cellpadding="0">
							<tr valign="top">
								<td class="ybox11td5"></td>
								<td class="ybox11td6">填写合同信息</td>
								<td class="ybox11td7"></td>
								<td class="ybox11td2"></td>
								<td class="ybox11td3"></td>
								<td class="ybox11td2"></td>
								<td class="ybox11td3"></td>
								<td class="ybox11td2"></td>
								<td class="ybox11td4"></td>
							</tr>
						</table></td>
				</tr>
			</table>
		</div>
		<div class="ybox02">
			<table width="100%" border="0" cellspacing="0" cellpadding="0"
				class="margb4">
				<tr>
					<td class="ybox03td1"></td>
					<td class="ybox03td2"></td>
					<td class="ybox03td3"></td>
				</tr>
				<tr>
					<td class="ybox03td4"></td>
					<td class="ybox03td5"><div class="ybox05 margb8">
							<dl>
								<dt>
									<strong>房间基本信息</strong>
								</dt>
							</dl>
						</div>
						<table width="100%" border="0" cellpadding="0" cellspacing="1"
							class="ybox04table">
							<tr>
								<td width="10%" class="ybox04tdl"><span class="red">*</span>签约项目</td>
								<td width="13%" class="ybox04tdr"><input id="project_name"
									disabled="disabled" name="project_name" type="text"
									class="black12" style="width: 90%;" />
									<div id="sdiv"></div></td>
								<td width="10%" class="ybox04tdl"><span class="red">*</span>签约楼栋</td>
								<td width="13%" class="ybox04tdr"><input name="build_name"
									disabled="disabled" class="black12" id="build_name"
									style="width: 90%;" /></td>
								<td width="10%" class="ybox04tdl"><span class="red">*</span>签约单元</td>
								<td width="13%" class="ybox04tdr"><input type="text"
									name="unit_code" disabled="disabled" class="black12"
									id="unit_code" style="width: 90%;" /></td>
								<td width="10%" class="ybox04tdl"><span class="red">*</span>签约房间</td>
								<td width="13%" class="ybox04tdr"><input type="text"
									name="room_code" disabled="disabled" class="black12"
									id="room_code" style="width: 90%;" /></td>
							</tr>
							<!-- 1111111111111111111111111111111111 -->
							<tr>
								<td width="10%" class="ybox04tdl"><span class="red">*</span>每平米房间单价</td>
								<td width="13%" class="ybox04tdr"><input
									disabled="disabled" id="unit_price" name="unit_price"
									type="text" class="black12" style="width: 90%;" /></td>
								<td width="10%" class="ybox04tdl"><span class="red">*</span>房间总价</td>
								<td width="13%" class="ybox04tdr"><input name="total"
									type="text" disabled="disabled" class="black12" id="total"
									style="width: 90%;" /></td>
								<td width="10%" class="ybox04tdl"><span class="red">*</span>购买面积</td>
								<td width="13%" class="ybox04tdr"><input
									disabled="disabled" name="pay_area" class="black12"
									id="pay_area" style="width: 90%;" /></td>
								<td width="10%" class="ybox04tdl"  colspan="3"></td>
								
							</tr>
						</table></td>
					<td class="ybox03td6"></td>
				</tr>
				<tr height="20">
					<td colspan="6" bgcolor="#e9f7ff"></td>
				</tr>
				<tr>
					<td class="ybox03td4"></td>
					<td class="ybox03td5"><div class="ybox05 margb8">
							<dl>
								<dt>
									<strong>订单信息</strong>
								</dt>
							</dl>
						</div>
						<table width="100%" border="0" cellpadding="0" cellspacing="1"
							class="ybox04table">
							<tr>
								<td width="15%" class="ybox04tdl">客户名称</td>
								<td width="18%" class="ybox04tdr"><input type="text"
									name="customer_name" disabled="disabled" style="width: 90%;"
									id="customer_name" />
									<div id="customer_div"></div></td>
								<td width="15%" class="ybox04tdl">保证金</td>
								<td width="18%" class="ybox04tdr"><input type="text"
									name="deposit" disabled="disabled" class="black12" id="deposit"
									style="width: 90%;" /></td>

							</tr>

							<tr>
								<td width="15%" class="ybox04tdl">付款方式</td>
								<td width="18%" class="ybox04tdr"><input type="text"
									name="pay_type_name" disabled="disabled" class="black12"
									id="pay_type_id" style="width: 90%;" /></td>
								<td width="15%" class="ybox04tdl">订单类型</td>
								<td width="18%" class="ybox04tdr"><input name="order_type"
									type="text" disabled="disabled" class="black12" id="order_type"
									style="width: 90%;" /></td>
							</tr>
						</table></td>
					<td class="ybox03td6"></td>
				</tr>
				<!-- -------------------------------------------------- -->
					<tr>
					<td class="ybox03td4"></td>
					<td class="ybox03td5"><div class="ybox05 margb8">
							<dl>
								<dt>
									<strong>合同内容明细</strong>
								</dt>
							</dl>
						</div>
						<table width="100%" border="0" cellpadding="0" cellspacing="1"
							class="ybox04table">
							
							<tr>
								<td width="15%" class="ybox04tdl">合同甲方</td>
								<td width="18%" class="ybox04tdr"><input type="text"
									name="first_party" class="black12" 
									id="first_party" style="width: 90%;" /></td>
								<td width="15%" class="ybox04tdl">合同乙方</td>
								<td width="18%" class="ybox04tdr"><input name="second_party"
									type="text"  class="black12" id="second_party"
									style="width: 90%;" /></td>
							</tr>
							<tr>
								<td width="15%" class="ybox04tdl">签约时间</td>
								<td width="18%" class="ybox04tdr">
								<input type="text" name="sign_time" class="black12" id="btn"
									onclick="J.calendar.get();" style="width: 90%;" />
								</td>
								<td width="15%" class="ybox04tdl">合同总价</td>
								<td width="18%" class="ybox04tdr">
								<input type="text" name="contract_total" class="black12" id="contract_total"
									 style="width: 90%;" />
								</td>
							</tr>
						<tr>
								<td width="15%" class="ybox04tdl">支付方式</td>
									<td width="18%" class="ybox04tdr">
									<select id="zffs">
										<option value="kapay.jsp">银行卡</option>
										<option value="baopay.jsp">支付宝</option>
									</select>
									</td>
									<td width="35%" class="ybox04tdl"></td>
								    <td width="18%" class="ybox04tdr"></td>
						  </tr>
							<tr >
								<td width="10%" class="ybox04tdl">合同内容</td>
								<td width="90%" class="ybox04tdr"  colspan="3">
								<textarea name="contract_content"  style="width: 100%;" id="contract_content" cols="300" rows="10" >
							    </textarea>
							    </td>
							</tr>

						</table></td>
					<td class="ybox03td6"></td>
				</tr>
				<!--  -->
				<tr>
					<td class="ybox03td7"></td>
					<td class="ybox03td8"></td>
					<td class="ybox03td9"></td>
				</tr>
				
			</table>
					<tr>
					<td class="ybox03td4"></td>
					<td class="ybox03td5">
						<table width="100%" border="0" cellpadding="0" cellspacing="1"
							class="ybox04table">

							<tr>
								<td width="18%" colspan="6" class="ybox04tdr">

									<dl>
										<dt>
											<strong>【注】</strong> </br>1.房间基本信息为自动生成</br> 2.订单消息自动生成</br>3.合同内容为必填选项
										</dt>
									</dl>
								</td>
							</tr>

						</table></td>
					<td class="ybox03td6"></td>
				</tr>
			<table width="380" border="0" align="center" cellpadding="0"
				cellspacing="0">
				<tr>
					<td height="60" align="center"><img
						src="images/bottoncommit.gif" style="cursor: pointer;" width="95"
						height="34" onclick="sendMassage()" /></td>
					<td height="60" align="center"><img
						src="images/bottonreset.gif" style="cursor: pointer;" width="95"
						height="34" onclick="ajaxReset()" /></td>
				</tr>
			</table>
		</div>
	</div>
	<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" >
  <div class="modal-dialog" role="document">
    <div class="modal-content" style="height: 500px; width: 420px">
      <div class="modal-header" style="background:#438eb9;">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title" id="myModalLabel">验证签约信息</h4>
      </div>
   
      <div class="modal-body">
 <div class="form-group" >
     <div id="massageid" style="width: 80%">
          <label for="inputEmail3"  class="col-sm-2 control-label" style="width: 100%">
           <b><h3>短信验证</h3></b><br/>
             <font id="checkmassageid">
             
             </font>
         </label>
    </div>
     </div>
     </div>
  <!--  <div class="col-sm-10">
     验证码： <input type="text" class="form-control" id="role_name" placeholder="role_name"/>
    </div>
 --> 
            <span class="input input--haruki" style="height:50px;" >
			<input class="input__field input__field--haruki" type="text" id="input-1" />
			<label class="input__label input__label--haruki" for="input-1">
				<span class="input__label-content input__label-content--haruki">请输入验证码</span>
			</label>
		</span>
 
      
       <div class="modal-footer">
        <input type="button" onclick="ajaxUpdate123()" value="　提　交 　" class="btn btn-success"/>
        <button type="button" class="btn btn-success" onclick="sendMassage()">　重新发送　</button>
      </div>
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font >
                   如果60秒内没有接收到消息，请点击重新发送。
      </font>

    </div>
  </div>
</div>
</body>
</html>
